<?php
error_reporting( E_ALL&~E_NOTICE );
$nr = $_GET['action'];
$file_path = "bow.txt";
$str = 0;
if(file_exists($file_path)){
	$fp = fopen($file_path,"r");
	$str = fread($fp,filesize($file_path));
	fclose($fp);
}
if($nr == "get"){
	echo "$str";
}
$ls = 0;
$a = 0;
if ($nr == "send"){
	$arr = explode(",",$str);
	$a = $_GET['text']-1;
	if($arr[$a] == "-1"){
		$arr[$a]="-3";
		echo $arr[$a];
		$myfile = fopen("bow.txt", "w");
		$txt = implode(",",$arr);
		fwrite($myfile, $txt);
		fclose($myfile);
	}
	else if($arr[$a] != "-3"){
	try{
		if ($arr[$a-1] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a+1] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a+10] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a+11] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a+9] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a-10] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a-11] == -1) {
			$ls = $ls +1;
		}
		if ($arr[$a-9] == -1) {
			$ls = $ls +1;
		}
		
	}catch(Exception $e){
	}
		$arr[$a] = $ls;
		$myfile = fopen("bow.txt", "w");
		$txt = implode(",",$arr);
		fwrite($myfile, $txt);
		fclose($myfile);
		echo $ls;
	}	
	
}
if($nr == "rmap"){
	$arr = array();
	for($i=0;$i<=99;$i++){
		$key = rand(1,11);
		if($key<=4){
			$arr[$i] = "-1";
		}else{
			$arr[$i] = "-2";
		}
	}$txt = implode(",",$arr);
	$myfile = fopen("bow.txt", "w");
	fwrite($myfile, $txt);
	fclose($myfile);
}
?>